package com.getword.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.getword.mongo.annotations.GeneratedLongValue;
import com.getword.utils.jsonserialize.UserBirthdayDateSerializer;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.util.Date;

@Document(collection="user")
@Getter
@Setter
@ToString
public class User implements Serializable {
    public interface UserSimpleView{}
    public interface UserDetailView extends UserSimpleView{}

    @Id
    @Field("_id")
    @GeneratedLongValue
    private long id;
    @Indexed(unique = true)
    private String loginName;
    private String password;
    private String username;
    @JsonSerialize(using = UserBirthdayDateSerializer.class)
    private Date birthday;
    private String gender;
    private String qq;
    private String image;
    private String role;
    private String intro;  // 简介
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date registerTime;

    private String openid;  //微信 的openID

    @DBRef
    private School school;

    public User() {
    }

    public User(long id) {
        this.id = id;
    }

    public User(long id, String loginName) {
        this.id = id;
        this.loginName = loginName;
    }
    public User(long id, String loginName, String username) {
        this.id = id;
        this.loginName = loginName;
        this.username = username;
    }
}
